//  
//   JKLrcTool.m
//   QQMusic
//  
//   Created by albert on 16/4/9.
//   Copyright (c) 2016年 albert. All rights reserved.
//  

#import "JKLrcTool.h"
#import "JKLrcLineModel.h"

@implementation JKLrcTool

+ (NSArray *)lrcToolWithLrcName:(NSString *)lrcName{
    //  1、拿到歌词文件的路径
    NSString *lrcPath = [[NSBundle mainBundle] pathForResource:lrcName ofType:nil];
    
    //  2、读取歌词
    NSString *lrcString = [NSString stringWithContentsOfFile:lrcPath encoding:NSUTF8StringEncoding error:nil];
    
    //  3、拿到歌词的数组，每行以换行符分隔
    NSArray *lrcArray = [lrcString componentsSeparatedByString:@"\n"];
    
    //  4、遍历每一句歌词，转成模型
    NSMutableArray *tempArray = [NSMutableArray array];
    for (NSString *lineString in lrcArray) {
        //  拿到每一句歌词
        /*
         [ti:心碎了无痕]
         [ar:张学友]
         [al:]
         */
        //  过滤不需要的歌词行
        if ([lineString hasPrefix:@"[ti:"] || [lineString hasPrefix:@"[ar:"] || [lineString hasPrefix:@"[al:"] || ![lineString hasPrefix:@"["]) {
            continue;
        }
        
        //  将歌词转成模型
        JKLrcLineModel *lrcLine = [JKLrcLineModel lrcLineWithLrcLineString:lineString];
        [tempArray addObject:lrcLine];
    }
    
    return tempArray;
}
@end